<?php

namespace utils\oss;

class OssService
{
    /**
     * 执行OSS上传
     * @param $tmpInfo
     * @return mixed|string
     * @throws \Exception
     */
    public static function handleOssUpload($tmpInfo)
    {
        $allowOss = config('rds.upload_enable_oss');
        $ossSelected = config('rds.upload_oss_selected');
        if ($allowOss === 1) {
            if ($ossSelected === 'aliyun_oss') {
                $url = AliyunOssService::upload($tmpInfo);
            }
            if ($ossSelected === 'qiniu_oss') {
                $url = QiniuOssService::upload($tmpInfo);
            }
        }
        return $url;
    }

    /**
     * 生成唯一文件名
     * @param $type
     * @param $tmpInfo
     * @return string
     */
    protected static function setPath($type, $tmpInfo)
    {
        //上传路径
        $filepath = date(config('rds.upload_sub_dir')) . '/' . gen_order_sn() . '.' . $tmpInfo['extension'];
        // 返回路径
        return $filepath;
    }
}